using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Hiro.Interfaces;
using Mono.Cecil;
using Mono.Cecil.Cil;

namespace Hiro
{
    /// <summary>
    /// Represents the default implementation of the <see cref="IServiceEmitter"/> class.
    /// </summary>
    public class ServiceEmitter : IServiceEmitter
    {
        /// <summary>
        /// Emits the instructions that will instantiate a service instance.
        /// </summary>
        /// <param name="dependencyMap">The dependency map that describes the dependencies in the current application.</param>
        /// <param name="newMethod">The method that will create the service itself.</param>
        /// <param name="IL">The <see cref="CilWorker"/> that points to the instructions of the method body.</param>
        /// <param name="currentService">The service that will be created.</param>
        public virtual void EmitService(MethodDefinition newMethod, CilWorker IL, ModuleDefinition hostModule, IService currentService, IDependencyMap dependencyMap)
        {
            var declaringType = newMethod.DeclaringType;

            // Instantiate the type
            var activationPoint = currentService.ActivationPoint;
            activationPoint.Emit(newMethod, IL, hostModule, dependencyMap);
        }
    }
}
